package com.woke.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.zhongcai.online.R;


/**
 * 作者 ： 林凤河
 * 创建时间：2016/11/1
 * 备注：
 */

public abstract class BaseFrag extends Fragment implements Toolbar.OnMenuItemClickListener {

	public Toolbar mToolbar;
	public TextView mToolbarTitle;

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setReenterTransition(true);
	}

	public abstract int getMenuId();

	public abstract void OnNavigationClickListener(View v);

	public abstract boolean OnMenuItemClickListener(MenuItem item);

	public void initToolbar(View rootView) {
		initToolbar (rootView, false);
	}

	public void initToolbar(View rootView, boolean isShowNav) {
		mToolbar = (Toolbar) rootView.findViewById (R.id.toolbar);
		mToolbarTitle = (TextView) rootView.findViewById (R.id.toolbar_title);
		if (mToolbar != null) {
			mToolbar.setTitle ("");
			if (getMenuId () > 0) {
				mToolbar.inflateMenu (getMenuId ());
			}
			mToolbar.setOnMenuItemClickListener (this);
			mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					OnNavigationClickListener (v);
				}
			});
			if (! isShowNav) {
				mToolbar.setNavigationIcon (null);
			}
		}
	}

	public void setTitle(String title) {
		if (mToolbarTitle != null) {
			mToolbarTitle.setText (title);
		}
	}

	@Override
	public boolean onMenuItemClick(MenuItem item) {
		return OnMenuItemClickListener (item);
	}

}
